/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-03-26
 * Time: 23:46
 */
public class BLOCKED {
    public static void main(String[] args) throws InterruptedException {
        Object locker = new Object();
        Thread thread1 = new Thread(()->{
            synchronized (locker){
                try {
                    Thread.sleep(1000000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        thread1.start();
        //thread1先拿到locker锁对象
        Thread thread2 = new Thread(()->{
            while (true) {
                synchronized (locker) {
                    System.out.println("Hello Thread2");
                }
            }
        });
        thread2.start();
        //sleep(1000)的作用是让thread2有足够用的时间执行到synchronized
        Thread.sleep(100);
        //获取线程状态
        //BLOCKED
        System.out.println(thread2.getState());
    }
}